package com.thiswhyme.log.config;

import com.thiswhyme.log.core.LogAspect;
import com.thiswhyme.log.core.LogListener;
import com.thiswhyme.log.core.LogPublisher;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;

/**
 * @description: 操作日志配置
 * @author: thiswhyme
 * @date: 2021/6/9
 */
@Import(AsyncConfig.class)
public class LogAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean(LogPublisher.class)
    public LogPublisher logPublisher(ApplicationContext applicationContext) {
        return new LogPublisher(applicationContext);
    }

    @Bean
    @ConditionalOnMissingBean(LogListener.class)
    public LogListener logListener() {
        return new LogListener();
    }

    @Bean
    @ConditionalOnMissingBean(LogAspect.class)
    public LogAspect logAspect(LogPublisher logPublisher) {
        return new LogAspect(logPublisher);
    }
}
